package dao.impl;

import dao.DeptDao;
import pojo.Dept;
import util.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class DeptDaoImpl implements DeptDao {
    @Override
    public List<Dept> listDept() {
        BaseDao bd=new BaseDao();
        List<Dept> list=new ArrayList<Dept>();
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            conn=bd.getConnection();
            String sql="select * from depts";
            ps=conn.prepareStatement(sql);
            rs=ps.executeQuery();
            while(rs.next()){
               Dept dt=new Dept();
               dt.setDname(rs.getString("DNAME"));
               dt.setDeptno(rs.getInt("DEPTNO"));
               dt.setLoc(rs.getString("LOC"));
               list.add(dt);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


        return list;
    }
}
